/**
 * 
 */
package com.I9lou.se.lurker.analyzer.support;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.lucene.analysis.Analyzer;

import com.I9lou.se.lurker.analyzer.AnalyzerFactory;

/**
 * Analyzer实例工厂的一个简单实现
 * @author chenwei
 * @date 2011-04-11
 * @ThreadSafe
 */
public class SimpleAnalyzerFactory implements AnalyzerFactory {
	
	private Analyzer defaultAnalyzer;
	
	private ConcurrentHashMap<String, Analyzer> analyzerPool = new ConcurrentHashMap<String, Analyzer>();
	
	public void setAnalyzerMap(Map<String, Analyzer> initialAnalyzerPool) {
		analyzerPool.putAll( initialAnalyzerPool );
	}
	
	public void setDefaultAnalyzer(Analyzer defaultAnalyzer) {
		this.defaultAnalyzer = defaultAnalyzer;
	}

	@Override
	public Analyzer getDefault() {
		return defaultAnalyzer;
	}
	
	@Override
	public Analyzer get(String analyzerName) {
		if( analyzerName==null || analyzerName.length()==0 )
			return getDefault();
		else
			return analyzerPool.get(analyzerName);
	}

}
